package com.ipfsemc.ipfsemc.service.imp;

import com.ipfsemc.ipfsemc.mapper.BankMapper;
import com.ipfsemc.ipfsemc.mapper.BankNameMapper;
import com.ipfsemc.ipfsemc.model.Bank;
import com.ipfsemc.ipfsemc.model.BankName;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class BankServiceImpl implements IBankService {
    @Autowired
    private BankMapper bankMapper;



    @Override
    public int add(Bank bank) {
        return bankMapper.insertSelective(bank);
    }

    @Override
    public int update(Bank bank) {
        return bankMapper.updateByPrimaryKeySelective(bank);
    }

    @Override
    public int del(Long bankId) {
        return bankMapper.deleteByPrimaryKey(bankId);
    }

    @Override
    public Bank selectByNum(Bank bank) {
        return bankMapper.selectByPrimaryKey(bank.getBankNum());
    }

    @Override
    public List<Bank> list(Bank bank) {
        List<Bank> list = bankMapper.list(bank);
        List<Bank> l=new ArrayList<>();
        for (Bank b:list){
            b.setBankNum(b.getBankNum().replaceAll("(\\d{4})\\d{4}(\\d{4})\\d{4}(\\d{3})", "$1****$2****$3"));
            l.add(b);
        }

        return l;
    }

    @Override
    public Bank selectBank(Long bankId) {
        return bankMapper.selectOne(bankId);
    }


}
